# CMakeLists.txt for csv_library

cmake_minimum_required(VERSION 3.16)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(csv_library)

message(STATUS "Library Using compiler: ${CMAKE_CXX_COMPILER}")

if (MSVC)
    add_compile_options(/EHsc)
    add_compile_options(/utf-8)
endif()


# 公共包含目录
set(PRO_ROOT ${PROJECT_SOURCE_DIR}/..)
set(CURL_INCLUDE_DIR ${PRO_ROOT}/include/csv)
set(CSV_INCLUDE_DIRS
    ${PRO_ROOT}/src/common/include
    ${PRO_ROOT}/include/csv
    ${PROJECT_SOURCE_DIR}/include
)

# 收集源文件
file(GLOB_RECURSE CSV_SOURCES
    ${PROJECT_SOURCE_DIR}/csv/*.cpp
    ${PRO_ROOT}/src/common/src/*.cpp
)
message(STATUS "csv_library Check CSV_SOURCES: ${CSV_SOURCES}")
message(STATUS "csv_library Check CSV_INCLUDE_DIRS: ${CSV_INCLUDE_DIRS}")

# set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# 动态库 (SHARED)
add_library(libcsvShared SHARED ${CSV_SOURCES})
# target_include_directories(csv_shared PUBLIC ${CSV_INCLUDE_DIRS})

include_directories(
    ${CSV_INCLUDE_DIRS}
    ${PRO_ROOT}/src/common/include
    ${PRO_ROOT}/thirdParty/spdlog-1.15.3/include
)

target_compile_definitions(libcsvShared PRIVATE CSVLIB_EXPORTS)  # 导出宏


# 统一设置输出路径
# 统一设置输出路径（覆盖所有平台）
set_target_properties(libcsvShared PROPERTIES
    OUTPUT_NAME "libcsvShared"  # 强制库名为 dllCsvStatic
    PREFIX ""                 # 移除 MinGW 的默认 lib 前缀
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Dll  # Windows: .dll
    LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Dll  # Linux: .so
    ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Dll  # 静态库（虽然动态库不需要，但避免冲突）
)

# 静态库 (STATIC)
add_library(libcsvStatic STATIC ${CSV_SOURCES})
target_include_directories(libcsvStatic PUBLIC ${CSV_INCLUDE_DIRS})
target_compile_definitions(libcsvStatic PRIVATE CSVLIB_STATIC) # 静态库导出宏
# 设置静态库输出路径
set_target_properties(libcsvStatic PROPERTIES
    OUTPUT_NAME "libcsvStatic"  # 强制库名为 csv_static
    PREFIX ""                 # 移除 MinGW 的默认 lib 前缀
    ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Lib  # 静态库 (.lib/.a)
)

# 调试输出
message(STATUS "CSV shared lib (DLL/SO) output: ${CMAKE_BINARY_DIR}/bin")
message(STATUS "CSV static lib (LIB/A) output: ${CMAKE_BINARY_DIR}/lib")

